package com.wl.application.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.wl.application.common.all.Result;
import com.wl.application.common.untils.HttpUtil;
import com.wl.application.common.untils.TokenUtil;
import com.wl.application.context.LoginLocalThread;
import com.wl.application.entity.LoginUser;
import com.wl.application.entity.UserToken;
import com.wl.application.services.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wl
 * @version 1.0
 * @date 2022/6/25
 * @description:
 */
@RestController

public class LoginController {


    @Autowired
    private LoginService loginService;
    @PostMapping("/login")
    public Result login(@RequestBody Map<String,String> map){
       return loginService.login(map);
    }

    @GetMapping("/tokeParse")
    public Result tokeParse(){
        //获取用户信息
        LoginUser token = LoginLocalThread.getLocal();

        return Result.ok(token);

    }
    /**
     * 注销
     */
    @GetMapping("/exit")
    public Result exit(){
        return loginService.exit();
    }

    /**
     * 获取当前访问的端口
     */

    @Value("${server.port}")
    private Integer port;


    @GetMapping("/port")
    public Result getPort(){
        Map<String,Object> map=new HashMap<>();
        map.put("port",port);
        map.put("ip", HttpUtil.getLinuxIp());
        return Result.ok(map);
    }
}
